<template>
    <a-spin :spinning="confirmLoading">
        <div>
            <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
                <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
                    selectedRowKeys.length }}</a>项
                <a style="margin-left: 24px" @click="onClearSelected">清空</a>
            </div>
            <a-checkbox @change="onTableTypeChange" defaultChecked style="float: right;">
                仅显示匹配客房类型
            </a-checkbox>
            <a-table ref="table" size="middle" :scroll="{ x: true }" bordered rowKey="id" :columns="columns"
                :dataSource="dataSource" :pagination="ipagination" :loading="loading"
                :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: 'radio', onChange: checkRoomType }"
                class="j-table-force-nowrap" @change="handleTableChange">
            </a-table>
        </div>
    </a-spin>
</template>

<script>

import { httpAction, getAction, putAction, postAction } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { validateDuplicateValue } from '@/utils/util'
import dayjs from 'dayjs'

export default {
    name: 'SanKeLiuFangForm',
    mixins: [JeecgListMixin],
    components: {
    },
    props: {
        //表单禁用
        disabled: {
            type: Boolean,
            default: false,
            required: false
        },
        room: {
            type: Object,
            required: true,
            default: () => { }
        }
    },
    data() {
        return {
            queryParam: {
                roomTypeCode: this.room.roomTypeCode
            },
            columns: [
                {
                    title: '#',
                    dataIndex: '',
                    key: 'rowIndex',
                    width: 60,
                    align: "center",
                    customRender: function (t, r, index) {
                        return parseInt(index) + 1;
                    }
                },
                {
                    title: '预订单号',
                    align: "center",
                    dataIndex: 'bookCode'
                },
                {
                    title: '房间号',
                    align: "center",
                    dataIndex: 'roomCode'
                },
                {
                    title: '预定人',
                    align: "center",
                    dataIndex: 'bookPerson'
                },
                {
                    title: '预定时间',
                    align: "center",
                    dataIndex: 'bookDate'
                },
                {
                    title: '房间类型',
                    align: "center",
                    dataIndex: 'roomTypeCode_dictText'
                },
                {
                    title: '入住模式',
                    align: "center",
                    dataIndex: 'checkInMode_dictText'
                },
                {
                    title: '预抵店时间',
                    align: "center",
                    dataIndex: 'dateArrival'
                },
                {
                    title: '预离店时间',
                    align: "center",
                    dataIndex: 'dateDeparture'
                },
                {
                    title: '联系电话',
                    align: "center",
                    dataIndex: 'photo'
                },
                {
                    title: '是否加床',
                    align: "center",
                    dataIndex: 'isExtraBed'
                },
                {
                    title: '额定房价',
                    align: "center",
                    dataIndex: 'ratedHousePrice'
                },
                {
                    title: '折扣',
                    align: "center",
                    dataIndex: 'discount'
                },
                {
                    title: '加床费',
                    align: "center",
                    dataIndex: 'extraBedAmount'
                },
                {
                    title: '房价',
                    align: "center",
                    dataIndex: 'roomPrice'
                },
                {
                    title: '早餐份数',
                    align: "center",
                    dataIndex: 'breakfastNum'
                },
                {
                    title: '客户单位',
                    align: "center",
                    dataIndex: 'company'
                },
                {
                    title: '优惠理由',
                    align: "center",
                    dataIndex: 'discountReason'
                },
                {
                    title: '备注',
                    align: "center",
                    dataIndex: 'remark'
                },
            ],
            confirmLoading: false,
            selectedRow: {},
            url: {
                list: '/room/roomBookInfo/list',
                add: "/room/roomBookInfo/add",
                edit: "/room/roomBookInfo/edit",
                queryById: "/room/roomBookInfo/queryById"
            }
        }
    },
    computed: {
        formDisabled() {
            return this.disabled
        },
    },
    methods: {
        onTableTypeChange(e) {
            if (e.target.checked) {
                this.queryParam.roomTypeCode = this.room.roomTypeCode
                this.searchQuery()
            } else {
                delete this.queryParam.roomTypeCode
                this.searchQuery()
            }
        },
        checkRoomType(key, row) {
            if (row[0].roomTypeCode !== this.room.roomTypeCode) {
                this.$message.warning("只能选择该房型下的房间");
                return false
            } else {
                this.selectedRowKeys.push(row[0].id)
                this.selectedRow = row[0]
                this.selectedRow.roomCode = this.room.roomCode
            }
        },
        add() {
            this.edit(this.selectedRow);
        },
        edit(record) {
            // this.model = Object.assign({}, record);
            this.visible = true;
            // console.log(this.model)
        },
        submitForm() {
            if (this.selectedRowKeys.length === 0 || !this.room.roomCode) {
                this.$message.warning("请选择房间")
                return false
            }
            const that = this;
            that.confirmLoading = true;
            console.log(that.selectedRow)
            putAction(this.url.edit, that.selectedRow).then(res => {
                if (res.success) {
                    that.$message.success("散客留房成功：" + that.selectedRow.roomCode);
                    that.$emit('ok');
                } else {
                    that.$message.warning(res.message);
                }
            }).finally(() => {
                that.confirmLoading = false;
            })

        },
    }
}
</script>